package lagou.FileTest;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class FileByteCopyTest {
    public static void main(String[] args) {
        FileInputStream file = null;
        FileOutputStream file2 = null;
        try {
            file = new FileInputStream("D:/B6UVQ@@8Q6DDI`1X[7~GIRD.png");
            int len = file.available();
            System.out.println("获取到的文件大小是："+len);
            file2 = new FileOutputStream("D:/复制的.png");
            System.out.println("玩命拷贝……");
//            byte[] by1 = new byte[len];
//            int res = file.read(by1);
//            System.out.println("实际读取到了："+res);
//            file2.write(by1);
//            while ((res = file.read()) != -1) {
//                file2.write(res);
//            }
            byte[] by2 = new byte[1024];
            int res = 0;
            while ((res = file.read(by2))!= -1){
                file2.write(by2,0,res);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            try {
                file2.close();
                file.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        System.out.println("加载完成");

    }
}
